package reflect;

import java.lang.reflect.Constructor;

/**
 * @Classname: ReflectDemo3
 * @Author: bromide
 * @CreateTime: 2022/4/18--11:21
 * @Version: V1.0
 * @Description: 使用有参构造器进行实例化
 */
public class ReflectDemo3 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Person");
        //获取Person()的构造器Person(String,int)
//        cls.getConstructor();//不穿任何参数，时获取的仍然时无参构造器
        Constructor c = cls.getConstructor(String.class, int.class);
        //new Person("李四",24);
        Object obj = c.newInstance("李四", 24);
        System.out.println(obj);
    }
}
